< previous page page_194 next page >

Page 194
Solution 15
What Time Zone Is It?
When you are working with a structure and you see data that seems correct near the start of the structure and meaningless data later in the structure, there is a good chance that you are dealing with an error in the structure declaration. API functions depend on all of the fields in the structure appearing in exactly the right offset in memory from the beginning of the structure. If one of the fields is declared incorrectly in your Visual Basic declaration, the location of all subsequent fields will be incorrect. In this case, the C declaration for the TIME_ZONE_INFORMATION structure is as follows:
typedef struct _TIME_ZONE_INFORMATION { // tzi
    LONG       Bias;
    WCHAR      StandardName[ 32 ];
    SYSTEMTIME StandardDate;
    LONG       StandardBias;
    WCHAR      DaylightName[ 32 ];
    SYSTEMTIME DaylightDate;
    LONG       DaylightBias;
} TIME_ZONE_INFORMATION;
We declared the StandardName field as follows:
StandardName(32) As Integer
AWCHAR is a wide 16-bit Unicode character, so, at first glance, Integer seems to be the correct type. On the other hand, you also know that many Win32 API functions have separate ANSI and Unicode entry points. When those functions have structure parameters and those structures contain strings, the string type varies depending on the entry point.
The question we have here is, which type are we dealing with? Does the GetTimeZoneInformation function have separate ANSI and Unicode entry points? If so, the StandardName and DaylightName fields of the TIME_ZONE_INFORMATION structure probably need to be changed to the Byte data type. If, however, the function has a single entry point, the StandardName and DaylightName fields probably really are 16-bit Unicode characters. Which is it?

 
< previous page page_194 next page >